﻿using Authentication.Core.Data;
using Authentication.Model.Interface;
using Authentication.Model.Model;
using Common.Contract.Authentication.Record;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Authentication.Provider
{
    public class AccountGroupCustomerProvider : GenericProvider, IAccountGroupCustomerProvider
    {
        public List<AccountGroupCustomer> RetrieveAccountGroupCustomer(UserRecord dao, bool isNew)
        {
            var data = repository.DbContext as AuthenticationEntities;
            var query = from x in data.AccountGroupCustomers
                        //where x.Dao.ToUpper() == dao.ToUpper()
                        select x;
            switch (dao.GroupIdentifier)
            {
                case "1":
                    query = query.Where(x => x.Dao.ToUpper() == dao.UserName.ToUpper());
                    break;
                case "2":
                    query = query.Where(x => x.Dao.ToUpper() == dao.UserName.ToUpper());
                    break;
                case "3":
                    query = query.Where(x => x.Dao.ToUpper() == dao.UserName.ToUpper());
                    break;
                case "4":
                    query = query.Where(x => x.Dao.ToUpper() == dao.Dao.ToUpper());
                    break;
                default:
                    break;
            }
            if (isNew)
            {
                query = query.Where(x => x.NewByCif > 0);
            }
            query = query.OrderBy(x => x.GroupName);
            return query.ToList();
        }
    }
}
